package transformation;

import java.util.Vector;

public class TransformationStack {

	private Vector<Matrix4f> inverseStack;
	private Vector<Matrix4f> stack;

	public TransformationStack() {
		initializeDataStructures();
	}

	public Matrix4f getInverseMatrix() {
		Matrix4f result = new Matrix4f();
		result.setIdentity();
		for (Matrix4f matrix : this.stack) {
			result = result.multiply(matrix);
		}
		result = result.tranpose();
		return result;
	}

	public Matrix4f getMatrix() {
		Matrix4f result = new Matrix4f();
		result.setIdentity();
		for (Matrix4f matrix : this.stack) {
			result = result.multiply(matrix);
		}
		return result;
	}

	private void initializeDataStructures() {
		stack = new Vector<Matrix4f>();
		inverseStack = new Vector<Matrix4f>();
	}

	public void pop() {
		this.stack.remove(stack.size() - 1);
		this.inverseStack.remove(0);
	}

	public void push(Matrix4f matrix, Matrix4f inverseMatrix) {
		this.stack.add(matrix);
		this.inverseStack.add(0, inverseMatrix);
	}
}
